
class SearchResult {
  final String? id;
  final String? content;
  final String? cover;
  final String? userId;
  final String? categoryId;
  final String? categoryName;
  final String? categoryPid;
  final String? categoryPName;
  final String? otherUserId;
  final String? album;
  final String? albumName;
  final int? imgCount;
  final int? status;
  final String? avatar;
  final String? username;
  final String? imgsUrl;
  final int? count;
  final List<String>? tagList;
  final String? viewCount;
  final String? agreeCount;
  final String? collectionCount;
  final String? commentCount;
  final String? time;

  SearchResult({
    required this.id,
    required this.content,
    required this.cover,
    required this.userId,
    required this.categoryId,
    required this.categoryName,
    required this.categoryPid,
    required this.categoryPName,
    required this.otherUserId,
    required this.album,
    required this.albumName,
    required this.imgCount,
    required this.status,
    required this.avatar,
    required this.username,
    required this.imgsUrl,
    required this.count,
    this.tagList,
    required this.viewCount,
    required this.agreeCount,
    required this.collectionCount,
    required this.commentCount,
    required this.time,
  });

  factory SearchResult.fromJson(Map<String, dynamic> json) {
    return SearchResult(
      id: json['id'],
      content: json['content'],
      cover: json['cover'],
      userId: json['userId'],
      categoryId: json['categoryId'],
      categoryName: json['categoryName'],
      categoryPid: json['categoryPid'],
      categoryPName: json['categoryPName'],
      otherUserId: json['otherUserId'],
      album: json['album'],
      albumName: json['albumName'],
      imgCount: json['imgCount'],
      status: json['status'],
      avatar: json['avatar'],
      username: json['username'],
      imgsUrl: json['imgsUrl'].toString(),
      count: json['count'],
      tagList: json['tagList'] != null ? List<String>.from(json['tagList']) : null,
      viewCount: json['viewCount'],
      agreeCount: json['agreeCount'],
      collectionCount: json['collectionCount'],
      commentCount: json['commentCount'],
      time: json['time'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'content': content,
      'cover': cover,
      'userId': userId,
      'categoryId': categoryId,
      'categoryName': categoryName,
      'categoryPid': categoryPid,
      'categoryPName': categoryPName,
      'otherUserId': otherUserId,
      'album': album,
      'albumName': albumName,
      'imgCount': imgCount,
      'status': status,
      'avatar': avatar,
      'username': username,
      'imgsUrl': imgsUrl,
      'count': count,
      'tagList': tagList,
      'viewCount': viewCount,
      'agreeCount': agreeCount,
      'collectionCount': collectionCount,
      'commentCount': commentCount,
      'time': time,
    };
  }
}

class SearchResultList {
  final int total;
  final List<SearchResult> data;

  SearchResultList({
    required this.total,
    required this.data,
  });

  factory SearchResultList.fromJson(List<dynamic> jsonList) {
    List<SearchResult> data = [];
    for (var item in jsonList) {
      if (item is Map<String, dynamic>) {
        data.add(SearchResult.fromJson(item));
      }
    }
    return SearchResultList(
      total: data.length, // Assuming total is the length of the list
      data: data,
    );
  }

  List<dynamic> toJson() {
    return data.map((item) => item.toJson()).toList();
  }
}
